import 'dart:ui' as ui;
import 'package:flutter/material.dart';

enum ScreenMode { mobile, pc }

class Screen {
  static double get width {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.size.width;
  }

  static double get height {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.size.height;
  }

  static double get scale {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.devicePixelRatio;
  }

  static double get textScaleFactor {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.textScaleFactor;
  }

  static double get navigationBarHeight {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.padding.top + kToolbarHeight;
  }

  static double get topSafeHeight {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.padding.top;
  }

  static double get bottomSafeHeight {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.padding.bottom;
  }

  static double designWidth = 375;
  // 如果超过maxDesignWidth 则直接采用PC布局模式
  static ScreenMode get mode {
    final double screenWidth = width > height ? height : width;
    return screenWidth > maxDesignWidth ? ScreenMode.pc : ScreenMode.mobile;
  }
  static double maxDesignWidth = 960;

  static double sizeByDesign(double designSize, [ double? designScreenWidth ]) {
    final double screenWidth = width > height ? height : width;
    final radio = (designScreenWidth ?? designWidth) / screenWidth;
    return designSize / radio;
  }
}